SetGfxDriver 1:Graphics 1024,768,8,2:SeedRnd MilliSecs() :SetBuffer FrontBuffer() 
Global in1,in2,sort1,sort2,zzz1
in1 = CreateBank(300):in2 = CreateBank(300)
Dim decode(4000000)
Dim encode(4000000):Dim aaa(160):Dim aaa1(160):sort1 = CreateBank(160):sort2 = CreateBank(60):Dim zzz(66666)
decodet()
While Not KeyHit(1) 
ClsColor 0,0,0
Cls
randnum()
getnums()
zzz1=zzz1+1
Flip
;WaitMouse() 
VWait 
Wend 

Function mod1(x)
While x>119
 x = x -120
Wend 
While  x<0 
 x = x +120
Wend 
Return x
End Function

Function mod2(x)
While x>255 
 x = x -256
Wend 
While  x<0 
 x = x +256
Wend 
Return x
End Function

Function fact_faza()
For unittest=1 To 120
	For i = 0 To 25 
	PokeInt in2,i*5, PeekInt (in1,i*5)
	Next 
	For hlfaza = 1 To unittest
		; ============= HIGH FAZA ===============
;		Goto lf
		For xt1=0 To 4
			For xt=0 To 4
				PokeInt sort1,xt*5,PeekInt (in2,xt1*20 + xt*5)	
				PokeInt sort2,xt*5,PeekInt (in2,xt1*20 + xt*5)					
			Next		
				For xt=0 To 4
					aaa(xt*5)=PeekInt (sort1,xt*5)+1
				Next
				For x=5 To 1 Step -1
				maxx =0
				For xt=0 To 4
				xx = aaa(xt*5):If maxx<xx Then maxx=xx:yy2=xt*5
				Next 
				aaa(yy2) =-10:aaa1(x*5)=PeekInt (sort2,yy2):PokeInt sort1,yy2,x
				Next
				ttt = Int(""+ PeekInt (sort1,0*5) +""+PeekInt (sort1,1*5) +""+PeekInt (sort1,2*5)+""+PeekInt (sort1,3*5)+""+PeekInt (sort1,4*5))
				xx = encode(ttt*5): 
;				DebugLog PeekInt (sort2,0)+" "+PeekInt (sort2,5)+" "+PeekInt (sort2,10)+" " + PeekInt (sort2,15) 
;				DebugLog xx		
				xx = mod1(xx +unittest) 
;				DebugLog xx						
				ttt1$ = decode(xx*5)
				x1=Mid$(ttt1$,1,1)
				x2=Mid$(ttt1$,2,1)
				x3=Mid$(ttt1$,3,1)
				x4=Mid$(ttt1$,4,1)
				x5=Mid$(ttt1$,5,1)								
;				DebugLog aaa1(5)+" "+aaa1(10)+" "+aaa1(15)+" " + aaa1(20)
;				DebugLog aaa1(x1*5)+" "+aaa1(x2*5)+" "+aaa1(x3*5)+" " + aaa1(x4*5): WaitMouse ()
				PokeInt in2,xt1*20 + 0*5,aaa1(x1*5)
				PokeInt in2,xt1*20 + 1*5,aaa1(x2*5)
				PokeInt in2,xt1*20 + 2*5,aaa1(x3*5)
				PokeInt in2,xt1*20 + 3*5,aaa1(x4*5)	
				PokeInt in2,xt1*20 + 4*5,aaa1(x5*5)				
		Next

		; ============ LOW FAZA ================
		For 	y1=0 To 25
		x = PeekInt (in2,y1*5)
		x1 = Int(Floor(x/256))
		x2 = x-x1*256
		x1 =mod2(x1 + unittest)
		x2 =mod2(x2 - unittest)
		x = x1*256+x2
		 PokeInt in2,y1*5,x
		Next
		.lf		
	Next
	eee = fact(fact(PeekInt(in2,0),PeekInt(in2,5),PeekInt(in2,10),PeekInt(in2,15),PeekInt(in2,20)),  fact(PeekInt(in2,0+25),PeekInt(in2,5+25),PeekInt(in2,10+25),PeekInt(in2,15+25),PeekInt(in2,20+25)), fact(PeekInt(in2,0+2*25),PeekInt(in2,5+2*25),PeekInt(in2,10+2*25),PeekInt(in2,15+2*25),PeekInt(in2,20+2*25)), fact(PeekInt(in2,0+3*25),PeekInt(in2,5+3*25),PeekInt(in2,10+3*25),PeekInt(in2,15+3*25),PeekInt(in2,20+3*25)), fact(PeekInt(in2,0+4*25),PeekInt(in2,5+4*25),PeekInt(in2,10+4*25),PeekInt(in2,15+4*25),PeekInt(in2,20+4*25)))
If eee = mod1(unittest - eee) Then zzz(zzz1)=zzz(zzz1)+1
Next

End Function

Function fact(x1,x2,x3,x4,x5)
        aaa(0)=x1:aaa(5)=x2:aaa(10)=x3:aaa(15)=x4:aaa(20)=x5
	For x=5 To 1 Step -1
	maxx =0
	For xt=0 To 4
	xx = aaa(xt*5):If maxx<xx Then maxx=xx:yy2=xt*5
	Next 
	aaa(yy2) =-10:PokeByte sort1,yy2,x
	Next
	ttt = Int(""+ PeekByte (sort1,0*5) +""+PeekByte (sort1,1*5) +""+PeekByte (sort1,2*5)+""+PeekByte (sort1,3*5)+""+PeekByte (sort1,4*5))
	xx = encode(ttt*5)
	Return xx
End Function

Function getnums()
	For y=0 To 4
	For x=0 To 4
	Color 0,255,0:Text 30+x*30,y*9+10,PeekInt(in1,5*(y*4+x)),False ,False 
	Next
	Next
	xx1=fact(PeekInt(in1,0),PeekInt(in1,5),PeekInt(in1,10),PeekInt(in1,15),PeekInt(in1,20)):Text 210,10,xx1,False ,False 
	xx2=fact(PeekInt(in1,0+25),PeekInt(in1,5+25),PeekInt(in1,10+25),PeekInt(in1,15+25),PeekInt(in1,20+25)):Text 210,19,xx2,False ,False 
	xx3=fact(PeekInt(in1,0+2*25),PeekInt(in1,5+2*25),PeekInt(in1,10+2*25),PeekInt(in1,15+2*25),PeekInt(in1,20+2*25)):Text 210,28,xx3,False ,False 
	xx4=fact(PeekInt(in1,0+3*25),PeekInt(in1,5+3*25),PeekInt(in1,10+3*25),PeekInt(in1,15+3*25),PeekInt(in1,20+3*25)):Text 210,37,xx4,False ,False 
	xx5=fact(PeekInt(in1,0+4*25),PeekInt(in1,5+4*25),PeekInt(in1,10+4*25),PeekInt(in1,15+4*25),PeekInt(in1,20+4*25)):Text 210,37+9,xx5,False ,False 
	Text 240,40,fact(xx1,xx2,xx3,xx4,xx5),False ,False 
	
	fact_faza()
	
	For y=0 To 4
	For x=0 To 4
	Color 255,255,0:Text 30+x*30,y*9+100,PeekInt(in2,5*(y*4+x)),False ,False 
	Next
	Next
	xx1=fact(PeekInt(in2,0),PeekInt(in2,5),PeekInt(in2,10),PeekInt(in2,15),PeekInt(in2,20))
	xx2=fact(PeekInt(in2,0+25),PeekInt(in2,5+25),PeekInt(in2,10+25),PeekInt(in2,15+25),PeekInt(in2,20+25))
	xx3=fact(PeekInt(in2,0+2*25),PeekInt(in2,5+2*25),PeekInt(in2,10+2*25),PeekInt(in2,15+2*25),PeekInt(in2,20+2*25))
	xx4=fact(PeekInt(in2,0+3*25),PeekInt(in2,5+3*25),PeekInt(in2,10+3*25),PeekInt(in2,15+3*25),PeekInt(in2,20+3*25))
	xx5=fact(PeekInt(in2,0+4*25),PeekInt(in2,5+4*25),PeekInt(in2,10+4*25),PeekInt(in2,15+4*25),PeekInt(in2,20+4*25))
	Text 240,82,fact(xx1,xx2,xx3,xx4,xx5),False ,False 
	ttt0=0
	For i=0 To zzz1
	If zzz(i) = 0 Then ttt0 = ttt0+1
	Color 255,255,0:Text (i*10) Mod 800,200+9*Int(i/80),Str(zzz(i))+",",False ,False 
    Next
	ttt0 = Ceil(ttt0 * 100 /  (zzz1+1))
	Color 255,255,0:Text 10,160,"0: " + ttt0 + " %",False ,False 
End Function


Function randnum()
For i = 0 To 25 
t = Rand(0,65535):PokeInt in1,i*5, t:PokeInt in2,i*5, t
Next 
End Function

Function decodet()
y=0
For x1=1 To 5
For x2=1 To 5
For x3=1 To 5
For x4=1 To 5
For x5=1 To 5
If((x1 <> x2) And (x1<>x3) And (x1<>x4)  And (x1<>x5) And (x2<>x3) And (x2<>x4) And (x2<>x5) And (x3<>x4) And (x3<>x5) And (x4<>x5)) decode(y*5) =x1+""+x2+""+x3+""+x4+""+x5:encode(Int(x1+""+x2+""+x3+""+x4+""+x5)*5)=y:y=y+1
Next
Next
Next
Next
Next
End Function